﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using Core.Dao;
using System.Data;

namespace Core.Business
{
    public class AccountTypeBus
    {
        private AccountTypeDao dao;
        public AccountTypeBus() {
            dao = new AccountTypeDao();
        }

        public bool insert(AccountType accountType) {
            return dao.insert(accountType);
        }

        public bool update(AccountType accountType) {
            return dao.update(accountType);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public AccountType get(int id) {
            DataTable dt = dao.get(id);
            AccountType accountType = new AccountType();

            if (dt.Rows.Count > 0)
            {
                accountType.Id = Convert.ToInt32(dt.Rows[0]["ACT_ID"]);
                accountType.Name = dt.Rows[0]["ACT_NAME"].ToString();
                accountType.Desc = dt.Rows[0]["ACT_DESC"].ToString();
            }
            return accountType;
        }

        public List<AccountType> getAll() {
            DataTable dt = dao.getAll();
            List<AccountType> list = new List<AccountType>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    AccountType accountType = new AccountType();
                    accountType.Id = Convert.ToInt32(dr["ACT_ID"]);
                    accountType.Name = dr["ACT_NAME"].ToString();
                    accountType.Desc = dr["ACT_DESC"].ToString();

                    list.Add(accountType);
                }

            }
            return list;
        }
    }
}
